package com.wanmait.scmdemo.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wanmait.scmdemo.entity.ProductCategory;
import com.wanmait.scmdemo.entity.ScmDictData;
import com.wanmait.scmdemo.service.ProductCategoryService;
import com.wanmait.scmdemo.service.ProductShowService;
import com.wanmait.scmdemo.service.ScmDictDataService;
import com.wanmait.scmdemo.util.AjaxResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 产品分类 前端控制器
 * </p>
 *
 * @author wanmait
 * @since 2024-11-26
 */
@RestController
@RequestMapping("/manage/productCategory")
public class ProductCategoryController {

    @Resource
    private ProductCategoryService productCategoryService;
    @Resource
    private ScmDictDataService scmDictDataService;

    @GetMapping("list")
    public AjaxResult list() {
        return AjaxResult.success(productCategoryService.list());
    }


    @GetMapping("getProductCategoryOption")
    //获取产品属性分类下拉框
    public AjaxResult getProductCategory() {
        return AjaxResult.success("查询成功", scmDictDataService.list("product_attribute"));
    }

    /*添加新类型*/
    @PostMapping("add")
    public AjaxResult add(@RequestBody ProductCategory productCategory) {
        return AjaxResult.success(productCategoryService.save(productCategory));
    }

    /*批量删除*/
    @PostMapping("deleteBatch")
    public AjaxResult deleteBatch(@RequestBody List<Integer> ids) {
        return AjaxResult.success(productCategoryService.removeBatchByIds(ids));
    }

    //根据产品类型查找
    @GetMapping("selectProducts")
    public AjaxResult selectProduct(String dataType) {
        return AjaxResult.success("查询成功").put("productCategorys", productCategoryService.selectProduct(dataType));
    }
}
